<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <table>
            <tr>
                <td>
                    <input type="text" placeholder="请输入关键" name="keyword"><input type="button" value="查找"
                        onclick="query()">
                </td>
                <td>
                    <input type="button" value="添加" onclick="add()">
                </td>
            </tr>
        </table>
    </div>
    <div>
        <table id="tb">
            <tr>
                <th>Id</th>
                <th>标题</th>
                <th>摘要</th>
                <th>内容</th>
                <th>分类</th>
                <th>作者</th>
                <th>发表时间</th>
                <th>操作</th>
            </tr>
            <tr class="tbData">
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td>
                    <input type="button" value="编辑" onclick="update()">
                    <input type="button" value="删除" onclick="del()">
                </td>
            </tr>
        </table>
    </div>

    <script src="./js/jquery-3.6.0.min.js"></script>
    <script src='./config/getUrlParam.js'></script>
    <script src="./js/api.js"></script>
    <script src="./js/init.js"></script>

    <script>
        function query(){
            let keyword = $('[name=keyword]').val()
            getListWithkeyword(keywrod);
        }

        function add(){
            window.location.href = 'CreateOrEdit.html'
        }

        function update(id){
            window.location.href = `CreateOrEdit.html?id=${id}`
        }

        function del(id){
            delBokeById(id).then(res=>{
                if (res.code === "1000") {
                    console.log(res);
                    let id = res.data.id;
                    $(`[key=${id}]`).remove();
                } else {
                    alert(res.msg);
                }
            })
        }
    </script>
</body>
</html>